package handin_6_Vending_Machine;

import java.util.ArrayList;

public class Inventory {
	private int inStore = 0;
	public double price = 0;
	public String name = "";
	public static ArrayList<String> commands = new ArrayList<String>();
	public static ArrayList<Integer> stock = new ArrayList<Integer>();
	public static ArrayList<Double> priceList = new ArrayList<Double>();
	
	public Inventory(int quantity)
	{
		inStore = quantity;
	}
	public Inventory(int quantity, double price)
	{
		inStore = quantity;
		this.price = price;
	}
	/**
	 * Create a new item inventory.
	 * @param name Name of item.
	 * @param quantity Quantity in stock.
	 * @param price Price.
	 */
	public Inventory(String name,int quantity, double price)
	{
		inStore = quantity;
		this.price = price;
		this.name = name;
		commands.add(name);
		stock.add(quantity);
		priceList.add(price);
	}
	
	//Mehods
	
	/*Builds an arrraylist with complete overview
	
	public static ArrayList<String> onSale()
	{
	ArrayList<String> onSale = new ArrayList<String>();
	for (int i=0;i<commands.size();i++)
	{
	onSale.add((commands.get(i))+":"+priceList.get(i)+" DKK, "+stock.get(i)+" in stock\n");
	}
	return onSale;
	}
	This works but ultimately prooved unflexible for printing the stock.
	*/
	
	/**
	 * Returns "name price Currency quantity in stock."
	 * ie. "Marsbar 10DKK 5 in stock."
	 */
	public String toString()
	{
		return name+" " +price+Coins.currency+" "+inStore+" in stock.";		
	}
	
	/**
	 * Sets the price of an item.
	 * @param newPrice The new price.
	 */
	public void setPrice(double newPrice)
	{
		price = newPrice;
		priceList.add(newPrice);
	}
	
	/**
	 * Sets a new quantity for an item. 
	 * @param newQuantity
	 */
	public void setQuantity(int newQuantity)
	{
		inStore=newQuantity;
		stock.add(newQuantity);
	}
	
	/**
	 * Renames an item.
	 * @param newName
	 */
	public void setName(String newName)
	{
		commands.remove(this.name);
		this.name=newName;
		commands.add(name);
	}
	
	/**
	 * Releases 1 piece of the item and updates the quantity. Sends a refill
	 * request when the item gets depleted.
	 * @return returns false if unable to release the item (ie. item sold out).
	 */
	public boolean release()
	{
		boolean wasReleased=true;
		if(inStore>0){
		System.out.println("One "+name+" was released.");
		inStore--;
		if (inStore == 0){System.out.println("Inventory depleted. A refill request was sendt to the supplier.");}
		}
		else{System.out.println("Item is sold out. A refill has already been requested.");
		wasReleased=false;}
		return wasReleased;
	}
	

	
	
	
}
